package kevin.study.zephyr.domain.model.base;

import java.io.Serializable;
import java.util.Date;

import kevin.study.zephyr.util.UUIDUtil;


/**
 * 基类
 * 
 * @author Kevin.Huang
 * @date 2007-9-20
 */
public class Base implements Serializable {

	/**
	 * 主键的名称
	 */
	public static final String FILTER_PK_ID = "uuid";

	/**
	 * 
	 */
	private static final long serialVersionUID = 3508708709361643419L;

	/**
	 * 各个对象的UUID
	 */
	private String uuid;

	private Date createTime;

	private Date modifyTime;

	/**
	 * 对各自对象的描述
	 */
	private String description;

	public Base() {
	}

	public Base(String uuid) {
		this.uuid = uuid;
	}

	/**
	 * 初始化,写入UUID 若已有UUID则不再写入
	 */
	public void init() {
		if (uuid == null) {
			uuid = UUIDUtil.generateUUID();
		}
		if (createTime == null) {
			createTime = new Date();
		}
		modifyTime = new Date();
	}

	/**
	 * @return the uuid
	 */
	public String getUuid() {
		return uuid;
	}

	/**
	 * @param uuid
	 *            the uuid to set
	 */
	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description
	 *            the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((uuid == null) ? super.hashCode() : uuid.hashCode());
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof Base)) {
			return false;
		}
		final Base other = (Base) obj;
		if (uuid == null) {
			if (other.uuid != null) {
				return false;
			} else {
				return super.equals(obj);
			}
		} else if (!uuid.equals(other.uuid)) {
			return false;
		}
		return true;
	}

	/**
	 * 判断对象是否已被初始化
	 * 
	 * @return true 对象已被初始化 false 对象没被初始化
	 */
	public boolean isInited() {
		return uuid == null ? false : true;
	}

	/**
	 * @return the createTime
	 */
	public Date getCreateTime() {
		return createTime;
	}

	/**
	 * @param createTime
	 *            the createTime to set
	 */
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	/**
	 * @return the modifyTime
	 */
	public Date getModifyTime() {
		return modifyTime;
	}

	/**
	 * @param modifyTime
	 *            the modifyTime to set
	 */
	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}
}
